home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
xobbs.arc
/
xomain.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-03
|
5KB
|
153 lines
/* Version 1.1 of W2XO ax25bbs for use with KA9Q net -Jim Durham, W2XO 2-14-89*/
/* second release version... beware even more than before! */
/* Code released to the Amateur Radio Packet community*/
#define MAIN 1
#include "xobbs.h"
main(argc,argv)
int argc;
char * argv[];
{
int fd1; /*file discriptor*/
int c; /* char holder */
char timstring[80]; /* log on time*/
char daepid[10]; /* mail daemon pid in ascii */
char *p; /* char pointer for copy operations*/
FILE* fp;
char *gettim();
int doquit();
void sndupkil();
signal(SIGALRM,sndupkil); /*set the watchdog timer*/
umask(0);
pid = getpid();
if(argc < 2){ /* if somebody goofs and doesnt type call */
local=1;
sprintf(prinbuf,"xobbs: Usage: xobbs calletters\n");
prinout(FLUSH);
sndupkil();
}
if(argc < 3){ /* This is invoked from shell not NET */
outfd=1;
infd=0;
local=1; /*local invocation*/
}
else{
rmsgqid=atoi(argv[2]); /*remote invocation*/
smsgqid=atoi(argv[3]); /*get message que id's*/
rcmsgqid=atoi(argv[4]);
scmsgqid=atoi(argv[5]);
local = 0;
}
getconfig(); /*read config information*/
gethighnum(0); /*get highnum and msgnum*/
if(!strcmp(argv[1],"forward")){
fwding=true;
local=false;
user.typ='F'; /*dummy type 'F' for "forwarding"*/
alarm(500); /*set the alarm*/
}
else{
getuser(argv[1]); /*get the user info */
alarm(180);
sprintf(prinbuf,"[XOBBS-V1.2-$]\n"); /* system id for MBL/RLI */
prinout(NOFLUSH);
if((user.typ != 'S') && (user.typ != 'B')){
if((fd1=open(motdfil,O_RDONLY)) < 0){ /*print error if no MOTD file*/
sprintf(prinbuf,"Missing MOTD file\n");
perror(prinbuf);
}
else{
fgetline(fd1,prinbuf);
prinout(NOFLUSH);
sprintf(prinbuf,"\n\n");
prinout(NOFLUSH);
}
close(fd1);
} /*if not sysop or bbs */
} /*forwarding is not true*/
fp=popen("ps -e | fgrep maildae","r"); /*get the pid of the maildaemon*/
p=daepid;
while(((c = getc(fp)) == ' ') && (c != EOF));
*p++ = c;
while(((c = getc(fp)) != ' ') && (c != EOF)){
*p++ = c; /*get the ascii pid of daemon*/
putchar(c);
}
*p='\0'; /*terminate pid string*/
pclose(fp); /*close the pipe*/
dpid=atoi(daepid); /*make it a global int */
/*log in the user*/
strcpy(timstring,gettim());
if( (fd1=open(logfile,O_RDWR|O_CREAT,0666)) < 0)
perror("bbs:Can't open log file");
sprintf(prinbuf,"%s %s\n",argv[1],timstring);
lseek(fd1,0L,2);
write(fd1,prinbuf,strlen(prinbuf));
close(fd1);
/*greet the unsuspecting user */
if(!fwding){
if((user.typ != 'S') && (user.typ != 'B')){
sprintf(prinbuf,"Hi, %s, Welcome to the %s BBS\n",user.name,my.call);
prinout(NOFLUSH);
sprintf(prinbuf,"New to you:%d - %d, %d Active Messages\n",user.highest,highnum,msgcnt);
prinout(NOFLUSH);
sprintf(prinbuf,"Logged in at: %s \n",timstring);
prinout(NOFLUSH);
}
if(user.typ != 'B'){
mailcheck(); /*check for user's mail*/
sprintf(prinbuf,"High %d, Active %d \n",highnum,msgcnt);
prinout(NOFLUSH);
if(dpid == 0){ /*warn user if mail daemon fails*/
sprintf(prinbuf,"Mail forwarder not running\n mail saved but not added to list\n");
prinout(NOFLUSH);
}
}
} /* if not a forwarding session*/
for(;;){ /*main loop*/
switch(user.typ){ /*select proper prompt*/
case 'F': alrmtim=600;
break;
case 'B':
case 'b': alrmtim = 600;
sprintf(prinbuf,"%s BBS>\n",my.call);
prinout(FLUSH);
break;
case 'S':
case 's':
case 'E':
case 'e': sprintf(prinbuf,"%s de %s BBS >\n",user.call,my.call);
prinout(FLUSH);
break;
default: sprintf(prinbuf,"%s de %s BBS (B,D,H,K,L,N,R,S,U,W) >\n",user.call,my.call);
prinout(FLUSH);
break;
} /*end of switch*/
if(!fwding){
do{
getline(0);
}while(inline[0] == '\0');
if(parse())
docmd(); /*parse it and do what's needed*/
}
else
docmd();
} /*for(;;); */ /* and keep on looping*/
}